home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15449 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  62 lines

  1. Path: news.accent.net!news
  2. From: sgirouard@accent.net (Simon Girouard)
  3. Newsgroups: comp.lang.c
  4. Subject: Copy Binary files to printer
  5. Date: 19 Apr 1996 02:02:06 GMT
  6. Organization: Accent Internet
  7. Message-ID: <4l6s6u$3cg@news.accent.net>
  8. NNTP-Posting-Host: 205.205.162.110
  9. Mime-Version: 1.0
  10. Content-Type: Text/Plain; charset=US-ASCII
  11. X-Newsreader: WinVN 0.99.7
  12.  
  13. Hi there!
  14.  
  15. I am writing a C program that simulate the DOS "COPY /B" command but send
  16. the file to a printer on a parallel port.
  17.  
  18. Here is the code I wrote :
  19.  
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. #define BUFSIZE 512
  25.  
  26. main()
  27. {
  28.   FILE *in, *pfd;
  29.   register i, test;
  30.   char buf[BUFSIZE];
  31.  
  32.   if ((pfd = fopen("lpt1", "wb")) == NULL)
  33.     exit(errno);
  34.  
  35.   if ((in = fopen("d:\\tmp\\test.tst", "rb")) == NULL)
  36.     exit(errno);
  37.  
  38.   do {
  39.     if ((i = fread(buf, 1, BUFSIZE, in)) == -1)
  40.       exit(errno);
  41.  
  42.     if ((test = fwrite(buf, 1, i, pfd)) == -1)
  43.       exit(errno);
  44.  
  45.   } while (i == BUFSIZE);
  46.  
  47.   fclose(in);
  48.   fclose(pfd);
  49.  
  50.   return 0;
  51. }
  52.  
  53.  
  54. The problem is that when writing to a file, it works fine but
  55. when writing to the parrallele port "LPT1" it seems to have trouble
  56. with the handshake and some garbage gets printed.
  57.  
  58. Is there a way to fix this !
  59.  
  60. Simon G.
  61.  
  62.